<?php namespace Health\Http\Controllers\Home;

use Log;
use Health\Http\Controllers\Home\BaseController;
use EasyWeChat;
use EasyWeChat\Message\Transfer;

class WeChatController extends BaseController
{
    /**
     * 处理微信的请求消息
     *
     * @return string
     */
    public function serve()
    {
        EasyWeChat::server()->setMessageHandler(function ($message) {
            switch ($message->MsgType) {
                case 'event':
                    return $this->handEvent($message);
                    break;
                case 'text':
                    return 'hello';
                    break;
                case 'image':
                    # 图片消息...
                    return "图片消息";
                    break;
                case 'voice':
                    return "语音消息";
                    break;
                case 'video':
                    # 视频消息...
                    return "视频消息";
                    break;
                case 'location':
                    # 坐标消息...
                    return "坐标消息";
                    break;
                case 'link':
                    # 链接消息...
                    return "链接消息";
                    break;
                // ... 其它消息
                default:
                    # code...
                    return "其他消息";
                    break;
            }
        });
        return EasyWeChat::server()->serve();
    }

    public function handEvent($message)
    {
        switch ($message->Event) {
            case 'subscribe':
                return "欢迎关注";
            case 'unsubscribe':
                return "取消关注";
            case 'SCAN':
                return 11;
            default:
                return "";


        }

    }

}